package com.example.as.Service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.as.Service.UserService;
import com.example.as.entity.User;
import com.example.as.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> loginIn(String account, String psw) {
        return userMapper.loginIn(account, psw);
    }

    @Override
    public int loginUp(String name, String account, String psw){return userMapper.loginUp(name, account, psw);}

    @Override
    public List<User> getUserList(String account) {
        List<User> userList = userMapper.getUserList(account);
        System.out.println(userList);
        return userList;
    }

    @Override
    public int delFri(String account1,String account2) {
        int a = userMapper.delByRelationAccount(account1, account2);
        int b = userMapper.delByRelationAccount(account2, account1);
        return a+b;
    }

    @Override
    public List<User> getUser(String account) {
        if (account != null) {
            return userMapper.selByUserAccount(account);
        } else return null;
    }

    @Override
    public int addFri(String account1, String account2) {
        int a = userMapper.addFri(account1, account2);
        int b = userMapper.addFri(account2, account1);
        return a+b;
    }

    @Override
    public List<User> getUserFriendList(String account){
        return userMapper.getUserFriendList(account);
    }
}
